<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
 
<!DOCTYPE html>
<html>
<head>
<meta charset="Utf-8">
<title>Insert title here</title>
<style>
.header {
  background-color: #f1f1f1;
  padding: 20px;
  text-align: center;
}

</style>
</head>
<body>
<div class="header">
<h1>数据库中的酒店</h1>
<hr>

<%


//加载驱动        <%@ include file="customer/auth.jsp"   在最上面
Class.forName("org.mariadb.jdbc.Driver");
//建立与数据库连接
Connection connection=DriverManager.getConnection("jdbc:mariadb://10.220.140.102:3366/studb11","stua","zHZUA65r");
//创建语句集
Statement stmt=connection.createStatement();
//结果查询
ResultSet rs = stmt. executeQuery("select*from hotel");
//显示RS结果
out.println("<table width='100%' border='1'>");
out.println("<tr><th>酒店名</th><th>城市</th><th>评分</th><th>id</th></tr>");
while (rs.next()){
	out.println("<tr>");
	out.println("<td>"+rs.getString("name")+"</td>");
	out.println("<td>"+rs.getString("city")+"</td>");
	out.println("<td>"+rs.getString("score")+"</td>");
	out.println("<td>"+rs.getString("id")+"</td>");
	
	out.println("</tr>");
}
out.println("</table>");
rs.close();
stmt.close();
connection.close();
%>

<hr>
<a href="addhotel.jsp" target="_blank">新增酒店</a>
</div>
</body>


</html>